#include <2025Linux.h>
int main(int argc, char *argv[])
{
    // ./11_mycp src dest
    ARGS_CHECK(argc,3);
    int fdr = open(argv[1], O_RDONLY);
    ERROR_CHECK(fdr,-1,"open fdr");
    int fdw = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC,0666);
    ERROR_CHECK(fdw,-1,"open fdw");

    char buf[1024*1024*4] = {0};
    while(1){
        memset(buf,0,sizeof(buf)); //读操作之前有个好习惯，是清空buffer
        ssize_t ret = read(fdr,buf,sizeof(buf));
        if(ret == 0){ // src已经读取完毕了
            break;
        }
        write(fdw,buf,ret);
    }

    close(fdw);//释放资源的顺序通常是后进先出
    close(fdr);
    return 0;
}

